/**
 *====================================================
 * 文件名称: NewsActionApiImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年9月21日			chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.news.action.v1;

import com.yuexunit.finance.news.action.v1.dto.NewsCategoryCastor;
import com.yuexunit.finance.news.action.v1.model.NewsCategory;
import com.yuexunit.finance.news.entity.NewsCategoryEntity;
import com.yuexunit.finance.news.entity.lexicon.CategoryTypeEnum;
import com.yuexunit.finance.news.service.NewsCategoryService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;

/**
 * @ClassName: NewsActionApiImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年9月21日 下午6:00:34
 */
@Implements(NewsCategoryActionApi.class)
public class NewsCategoryActionApiImpl implements NewsCategoryActionApi {

	private NewsCategoryService newsCategoryService = ComponentFactory.loadClass(NewsCategoryService.class);

	@Override
	public String createNewsCategory(String categoryName, Integer categoryType) {
		NewsCategoryEntity e = new NewsCategoryEntity();
		e.setCategoryName(categoryName);
		e.setCategoryType(CategoryTypeEnum.valueOf(categoryType));
		return String.valueOf(newsCategoryService.createNewsCategory(e));
	}

	@Override
	public void updateNewsCategory(Long newsCategoryId, Integer categoryType, String categoryName) {
		NewsCategoryEntity e = new NewsCategoryEntity();
		e.setCategoryName(categoryName);
		e.setNewsCategoryId(newsCategoryId);
		e.setCategoryType(CategoryTypeEnum.valueOf(categoryType));
		newsCategoryService.updateNewsCategory(e);
	}

	@Override
	public void disableNewsCategory(Long newsCategoryId) {
		newsCategoryService.disableNewsCategory(newsCategoryId);
	}

	@Override
	public NewsCategory inquireNewsCategoryDetail(Long newsCategoryId) {
		NewsCategoryEntity entity = newsCategoryService.inquireNewsCategoryDetail(newsCategoryId);
		NewsCategory newsCategory = NewsCategoryCastor.fromNewsCategoryEntity(entity);
		return newsCategory;
	}

	@Override
	public PageList<NewsCategory> inquireNewsCategoryPageList(String categoryName, String updateFromTime,
			String updateToTime, PageCriteria page) {
		return inquireCategoryPageList(categoryName, CategoryTypeEnum.INFORMATION.ordinal(), updateFromTime,
				updateToTime, page);
	}

	@Override
	public PageList<NewsCategory> inquireCategoryPageList(String categoryName, Integer categoryType,
			String updateFromTime, String updateToTime, PageCriteria page) {
		CategoryTypeEnum _categoryType = null;
		if (categoryType != null) {
			_categoryType = CategoryTypeEnum.valueOf(categoryType);
		}
		PageList<NewsCategoryEntity> pageList = newsCategoryService.inquireNewsCategoryList(categoryName, _categoryType,
				updateFromTime, updateToTime, page);
		PageList<NewsCategory> list = new PageList<NewsCategory>(page, pageList.getTotalRecordCount());
		for (NewsCategoryEntity entity : pageList) {
			list.add(NewsCategoryCastor.fromNewsCategoryEntity(entity));
		}
		return list;
	}
}